import requests
from api.global_conf import BASEURL, LOGPATH
from utils.index import Logs
log = Logs(LOGPATH)


def getCheckImg():
    try:
        res = requests.get(BASEURL + "/shop/mcheckImg")
    except Exception as result:
        log.error(f'接口访问失败: /shop/mcheckImg \n报错信息: {result}')
    else:
        log.info(f'接口访问成功: /shop/mcheckImg \n访问数据: {res.text}')
        return res


def register(data, headers):
    try:
        res = requests.post(BASEURL + "/shop/mregist", data=data, headers=headers)
    except Exception as result:
        log.error(f'接口访问失败: /shop/mregist \n报错信息: {result}')
    else:
        log.info(f'接口访问成功: /shop/mregist \n访问数据: {res.text}')
        return res


def login(data):
    try:
        res = requests.post(BASEURL + "/shop/mlogin", data=data)
    except Exception as result:
        log.error(f'接口访问失败: /shop/mlogin \n报错信息: {result}')
    else:
        log.info(f'接口访问成功: /shop/mlogin \n访问数据: {res.text}')
        return res
